#!/usr/bin/env bash

# 当使用未初始化的变量时，程序自动退出
set -u

# 当任何一行命令执行失败时，自动退出脚本
set -e

# 在运行结果之前，先输出执行的那一行命令
set -x

APP_PATH="/Users/dolphin/source/dabai/microservice"
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home"

# 更新公共依赖包
cd ${APP_PATH}/soa-misc
git pull
mvn clean install -e -U

# 启动Spring Eureka注册中心
EUREKA_APP_NAME="eureka-servic"
count=`ps -ef | grep ${EUREKA_APP_NAME} | grep -v "grep" | wc -l`
if [[ ${count} -lt 1 ]]; then
    cd ${APP_PATH}/eureka-service
    nohup ${JAVA_HOME}/bin/java -jar ${APP_PATH}/eureka-service/target/eureka-service-1.0.0-RELEASE.jar &
else
    echo "process aready exists!"
fi

# 基础服务-用户
USER_SERVICE_NAME="soa-user-service"
count=`ps -ef | grep ${USER_SERVICE_NAME} | grep -v "grep" | wc -l`
if [[ ${count} -lt 1 ]]; then
    cd ${APP_PATH}/soa-user/soa-user-service
    git pull origin develop
    mvn clean install -e -U
    nohup ${JAVA_HOME}/bin/java -jar ${APP_PATH}/soa-user/soa-user-service/target/soa-user-service-1.0.0-SNAPSHOT.jar &
else
    echo "process aready exists!"
fi

# 基础服务-钱包
WALLET_SERVICE_NAME="soa-wallet-service"
count=`ps -ef | grep ${WALLET_SERVICE_NAME} | grep -v "grep" | wc -l`
if [[ ${count} -lt 1 ]]; then
    cd ${APP_PATH}/soa-wallet/soa-wallet-service
    git pull origin master
    mvn clean install -e -U
    nohup ${JAVA_HOME}/bin/java -jar ${APP_PATH}/soa-wallet/soa-wallet-service/target/soa-wallet-service-1.0.0-SNAPSHOT.jar &
else
    echo "process aready exists!"
fi










